from rest_framework import status


class BaseException(Exception):
    """基础异常类"""

    def __init__(self, message=""):
        self.msg = message
        super().__init__(self.message)
    def __str__(self):
        return self.msg

class ServiceException(BaseException):
    """
        Service层异常基类，
        ：Service层出现的异常需要继承此基类
        @param message: 返回信息
        @param code: 状态码，请使用rest_framework.status中的存在的状态码，务要自定义
    """

    def __init__(self, message, code=None):
        self.msg = message
        self.code = code


class UnexpectedException(BaseException):
    """
        未预料到的异常
    """

    def __init__(self, message):
        self.msg = message
        self.code = status.HTTP_500_INTERNAL_SERVER_ERROR
